import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd())
  console.log('VITE_API_BASE:', env.VITE_API_BASE)
  return {
    plugins: [vue()],
    server: {
      host: '0.0.0.0',
      port: 3000,
      proxy: {
        '/api': {
          target: env.VITE_API_BASE,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        },
        '/users': {
          target: env.VITE_API_BASE,
          changeOrigin: true
        },
        '/uploads': {
          target: env.VITE_API_BASE,
          changeOrigin: true
        },
        '/login': {
          target: env.VITE_API_BASE,
          changeOrigin: true
        }
      }
    }
  }
}) 